package org.gorkr.api;


import io.swagger.annotations.ApiOperation;
import org.gorkr.domain.JsonResponse;
import org.gorkr.domain.User;
import org.gorkr.service.IUserService;
import org.gorkr.service.util.RSAUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author gorkr
 * @since 2022-08-12
 */
@RestController
@RequestMapping("/dao/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     *
     */
    @GetMapping("/users")
    public JsonResponse<User> getUserInfo() {
        return null;
    }

    /**
     * rsa公钥获取接口
     *
     * @return
     */
    @ApiOperation(value = "rsa公钥获取")
    @GetMapping("/rsa-pks")
    public JsonResponse<String> getRsaPublicKey() {
        String pk = RSAUtil.getPublicKeyStr();
        return JsonResponse.success(pk);
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    @ApiOperation(value = "添加用户")
    @PostMapping("/users")
    public JsonResponse<String> addUser(@RequestBody User user){
        userService.addUser(user);
        return JsonResponse.success();
    }

}
